package com.zhongyewx.teachercert.framework.glide;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomViewTarget;
import com.zhongyewx.teachercert.R;
import com.zhongyewx.teachercert.utils.ZYDensityUtil;

public class ZYGlideUtil {
    //圆形图片
    public static void LoadCircleImage(Context context, String url, ImageView imageView) {
        GlideApp.with(context).load(url)
                .centerCrop()
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_background)
                .transform(new ZYGlideCircleTransform())
                .into(imageView);
    }

    //圆形图片设置占位图
    public static void LoadCircleImage(Context context, String url, ImageView imageView, int placeholderResourceId, int errorResourceId) {
        GlideApp.with(context).load(url)
                .centerCrop()
                .placeholder(placeholderResourceId)
                .error(errorResourceId)
                .transform(new ZYGlideCircleTransform())
                .into(imageView);
    }

    //一般图片
    public static void LoadImage(Context context, String url, ImageView imageView) {
        GlideApp.with(context).load(url)
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_background)
                .into(imageView);
    }

    //一般图片设置占位图
    public static void LoadImage(Context context, String url, ImageView imageView, int placeholderResourceId, int errorResourceId) {
        GlideApp.with(context).load(url)
                .placeholder(placeholderResourceId)
                .error(errorResourceId)
                .into(imageView);
    }

    //圆角图片
    public static void LoadCornersImage(Context context, String url, ImageView imageView, int num) {
        RoundedCorners roundedCorners = new RoundedCorners(num);
        GlideApp.with(context).load(url)
                .centerCrop()
                .apply(RequestOptions.bitmapTransform(roundedCorners))
                .into(imageView);
    }

    //瀑布流图片
    public static void LoadStaggeredImage(final Context context, String url, final ImageView imageView) {
        int screenWidth = ZYDensityUtil.getScreenWidth(context);
        int width = screenWidth / 2;
        GlideApp.with(context).load(url).override(width, CustomViewTarget.SIZE_ORIGINAL).fitCenter().into(imageView);
    }



}
